/*************************
查看
* */
<template>
  <div>
    <el-dialog
      title="事件考核修改"
      :close-on-click-modal="true"
      :visible.sync="visible"
      top="8vh"
      width="70%"
      @close="closeUpdateDialog()"
    >
        <el-form ref="dataForm" :model="dataForm"   label-width="100px"  class="boxsty" @keyup.enter.native="dataFormSubmit()">
          <el-form-item label="标题：" prop="sjbt">
            <span>{{dataForm.sjbt}}</span>
          </el-form-item>

          <el-form-item label="考核周期：" prop="khzq">
            <span>{{dataForm.khzq}}</span>
          </el-form-item>

          <el-form-item label="描述：" prop="sjdesc">
            <span>{{dataForm.sjdesc}}</span>
          </el-form-item>

          <el-form-item label="考核对象：">
            <el-table
              ref="multipleTable"
              :data="khrNameList"
              height="250"
              style="width: 100%;"
              tooltip-effect="dark"
            >
              <el-table-column type="index"   width="70" align="center" label="序号" ></el-table-column>

              <el-table-column
                v-if="showRY"
                prop="username"
                label="员工编号" min-width="120" align="center"  show-overflow-tooltip>
              </el-table-column>
              <el-table-column
                v-if="showRY"
                prop="realname"
                label="姓名" min-width="120" align="center"  show-overflow-tooltip>
              </el-table-column>
              <el-table-column
                v-if="showRY"
                prop="deptName"
                label="部门" min-width="120" align="center"  show-overflow-tooltip>
              </el-table-column>

              <el-table-column
                v-if="!showRY"
                prop="deptName"
                label="机构名称"
                min-width="120" align="center"  show-overflow-tooltip>
              </el-table-column>


            <el-table-column
              prop="lbms"
              label="类别" width="120" align="center">
             <!-- <template slot-scope="scope">
                      <el-select v-model="scope.row.lb" placeholder="请选择类别域">
                        <el-option label="类别1" value="1"></el-option>
                        <el-option label="类别2" value="2"></el-option>
                      </el-select>
              </template>-->
            </el-table-column>
            <el-table-column
            prop="yjms"
            align="center"
            label="依据"  width="120"  show-overflow-tooltip>
          </el-table-column>
            <el-table-column
              prop="bz"
              align="center"
              label="标准" width="120" show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              prop="zbgz"
              align="center"
              label="指标规则" width="120" show-overflow-tooltip>
            </el-table-column>

              <el-table-column
                prop="jjx"
                header-align="center"
                width="120"
                align="center"
                label="奖金项"
                show-overflow-tooltip
              ></el-table-column>

              <el-table-column
                prop="jkjj"
                header-align="center"
                width="120"
                align="center"
                fixed="right"
                label="加扣奖金"
                show-overflow-tooltip
              ></el-table-column>

            <el-table-column
              fixed="right"
              align="center"
              prop="jkfz"
              label="加扣分值" width="100"  show-overflow-tooltip>
            </el-table-column>

              <el-table-column
                align="center"
                fixed="right"
                prop="xgjj"
                label="评审奖金" width="100" >
                <template slot-scope="scope">
                  <el-input v-model="scope.row.xgjj"
                            oninput="value=value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace(/(\.\d+)\./g, '$1').replace(/^0+(\d)/, '$1').replace(/(\d{15})\d*/, '$1').replace(/(\.\d{2})\d*/, '$1')"

                  ></el-input><!--@blur="xgjjChange"-->
                </template>
              </el-table-column>

            <el-table-column
              align="center"
              fixed="right"
              prop="xgfz"
              label="评审分值" width="100" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.xgfz"
                          oninput="value=value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace(/(\.\d+)\./g, '$1').replace(/^0+(\d)/, '$1').replace(/(\d{15})\d*/, '$1').replace(/(\.\d{2})\d*/, '$1')"
                ></el-input><!--@blur="xgfzChange"-->
              </template>
            </el-table-column>



          </el-table>
          </el-form-item>

        </el-form>

      <span slot="footer" class="dialog-footer">
         <el-button type="primary" plain @click="saveXgfz('dataForm')" v-loading="isSubmit" >保存</el-button><!--:disabled="canSubmit"-->
         <el-button type="primary" plain @click="closeUpdateDialog()">返回</el-button>
      </span>
    </el-dialog>
  </div>
</template>


<script>
    import {saveScore} from "@/api/dailyExamine/eventExamine/eventReview.js";
    export default {
        data() {
            return {
                showRY:true,
                khrNameList: [],
                visible: false,
                dataForm: {},
                isSubmit: false, //保存按钮的loading
                canSubmit:true
            };
        },
        watch: {},
        created() {},
        methods: {
            //初始化
            csh() {
                this.dataForm = {};
            },
            init(obj) {
                if (obj) {
                    this.dataForm = obj;
                    this.khrNameList = obj.khdxList;

                    this.showRY = obj.khtype=='ry'?true:false;
                    this.$nextTick(() => {
                        this.$refs.multipleTable.doLayout();
                    })
                }
                this.visible = true;
            },

            closeUpdateDialog() {
                this.visible = false;
                this.$emit("closeUpdateDialog");
            },
            handleChange(value) {
                console.log(value);
            },
            //修改分数
            saveXgfz(formName){
                this.isSubmit = true;
                        // var flag = this.checkFlag(this.khrNameList) ;
                        // if(flag){
                            this.dataForm.sjkhdxList = this.khrNameList;
                            saveScore(this.dataForm).then((res)=>{
                                this.isSubmit = false;
                                this.$emit("refreshDataList");
                                this.closeUpdateDialog();
                                this.$message.success("修改成功");
                            })
                        // }else{
                        //     this.$message.error("加扣奖金列和加扣分值列至少有一列全部不为空");
                        // }

            },
            // xgfzChange(e){ //修改分值
            //     this.dataForm.xgfz = e.target.value
            // },
            // xgjjChange(e){ //修改奖金
            //     this.dataForm.xgjj = e.target.value
            // },
            showCanSubmit() {
                let tempArray = [];
                let tempArray1 = [];

                this.tableData.map(it => {
                    it.pfxxChildrenList.map(itt => {
                        tempArray.push(itt.qzSum);
                    });
                    tempArray1.push(it.qzSum);
                });
                let flag = tempArray.some(it => {
                    return it !== 100;
                });
                let flag1 = tempArray1.some(it => {
                    return it !== 100;
                });
                if (flag || flag1) {
                    this.canSubmit = true;
                } else {
                    this.canSubmit = false;
                }
            },
            //校验是否有空值
            checkFlag(arr){
               var flag1 =  arr.every(it=>{
                    return it.xgfz ;
                });
               var flag2 = arr.every(it=>{
                   return it.xgjj ;
               })
                console.log('flag1:'+flag1)
                console.log('flag2:'+flag2)

                return flag1 || flag2 ;
            }

        }
    };
</script>
<style scoped>
  /deep/.boxsty{padding: 20px 30px!important;}
  /deep/.el-table th{padding: 5px!important;}

  .el-divider {
    background-color: #fff;
  }
  .tree-box {
    height: 500px;
    overflow: auto;
  }
</style>
